package com.trussell.genesis.windowutils.menus;

import javax.swing.ButtonGroup;
import javax.swing.JMenu;
import javax.swing.JRadioButtonMenuItem;

import com.trussell.genesis.GenesisImplementor.Mode;
import com.trussell.genesis.windowutils.listeners.ModeActionListener;

/**
 * This class helps reduce the number of lines of code
 * in Genesis.java by taking the GUI and controller 
 * construction of the Tool menu and placing it into
 * this class.
 * @author Tyler Trussell
 */
public class ToolMenu extends JMenu{
	
	private static final long serialVersionUID = 1L;
	
	private JRadioButtonMenuItem worldEditor;
	private JRadioButtonMenuItem terrainEditor;
	private JRadioButtonMenuItem effectsEditor;

	/**
	 * Returns a GenesisToolMenu, which contains the prepared
	 * JMenuItems necessary. They have already been bound to
	 * listeners.
	 */
	public ToolMenu() {
		super("Tools");
		
		//TODO add accelerators
		ButtonGroup modeGroup = new ButtonGroup();
		worldEditor = new JRadioButtonMenuItem("World Editor", true);
		terrainEditor = new JRadioButtonMenuItem("Terrain Editor", false);
		effectsEditor = new JRadioButtonMenuItem("Effects Editor", false);
		
		worldEditor.addActionListener(new ModeActionListener(Mode.NONE));
		terrainEditor.addActionListener(new ModeActionListener(Mode.TERRAIN_EDIT));
		effectsEditor.addActionListener(new ModeActionListener(Mode.EFFECTS_EDIT));
		
		modeGroup.add(worldEditor);
		modeGroup.add(terrainEditor);
		modeGroup.add(effectsEditor);
		
		add(worldEditor);
		add(terrainEditor);
		add(effectsEditor);
	}
	
	public void setMode(Mode mode) {
		switch(mode) {
		case NONE:
			worldEditor.setSelected(true);
			break;
		case TERRAIN_EDIT:
			terrainEditor.setSelected(true);
			break;
		case EFFECTS_EDIT:
			effectsEditor.setSelected(true);
			break;
		}
	}
}
